import axios from "../axios";
import qs from "qs";
// getAccessToken
export const getAccessToken = ({ username, password }) => {
  let data = {
    grant_type: "password",
    username: username,
    password: password,
    scope: "all",
  };
  return axios.request({
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      Authorization: "Basic " + window.btoa("cxrt-ims-web" + ":" + "000000"),
    },
    transformRequest: [
      function(data) {
        data = qs.stringify(data);
        return data;
      },
    ],
    url: "/oauth/token",
    params: data,
    method: "get",
  });
};

// postAccessToken
export const login = ({ username, password }) => {
  let data = {
    grant_type: "password",
    username: username,
    password: password,
    scope: "all",
  };
  return axios.request({
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      Authorization: "Basic " + window.btoa("cxrt-ims-web" + ":" + "000000"),
    },
    transformRequest: [
      function(data) {
        data = qs.stringify(data);
        return data;
      },
    ],
    url: "/oauth/token",
    data,
    method: "post",
  });
};
